class Solution {
public:
    int uniquePaths(int m, int n) {
        m--; n--;
        if (n > m) {
            n ^= m;
            m ^= n;
            n ^= m;
        }
        return (int)(jc2(m + n, m) / jc(n));
    }
    long long jc(int n)
    {
        if (n <= 1)return 1;
        long long ans = n;
        while (--n)ans *= n;
        return ans;
    }
    long long jc2(int m, int n)
    {
        if (m <= n)return 1;
        long long ans = m;
        while (--m > n)ans *= m;
        return ans;
    }
};